package com.zcb.myrxjavathreecache;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;

import com.zcb.myrxjavathreecache.modle.ImageBean;
import com.zcb.myrxjavathreecache.presenter.ImagePresenter;
import com.zcb.myrxjavathreecache.presenter.ImagePresenterImpl;
import com.zcb.myrxjavathreecache.view.MyView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements MyView{

    private ImagePresenter imagePresenter;
    private RecyclerView recyclerView;
    private DemoAdapter adapter;
    private ArrayList<String> imageBeanList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imagePresenter=new ImagePresenterImpl(this);
        imagePresenter.loadImgList(30,1);
        adapter=new DemoAdapter(this,this);
        imageBeanList=new ArrayList<String>();
        recyclerView= (RecyclerView) findViewById(R.id.my_recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setAdapter(adapter);

    }

    @Override
    public void showImgs(List<ImageBean> imageList) {
        ArrayList list=new ArrayList();
        for (ImageBean bean : imageList){
            list.add(bean.url);
//            adapter.notifyDataSetChanged();
            Log.i("bean",bean.url+" "+bean.desc);
        }
        imageBeanList.addAll(list);
        adapter.replaceAll(imageBeanList);
//        adapter.notifyDataSetChanged();


    }
//    public ArrayList<String> getData() {
//        ArrayList<String> list = new ArrayList<>();
//        for (String url : ImageUtil.imageUrls) {
//            list.add(url);
//        }
//        return list;
//    }
}
